package cn.tedu.tmall.admin.content.dao.persist.repository.impl;

import cn.tedu.tmall.admin.content.dao.persist.mapper.CategoryMapper;
import cn.tedu.tmall.admin.content.dao.persist.repository.ICategoryRepository;
import cn.tedu.tmall.admin.content.pojo.entity.Category;
import cn.tedu.tmall.admin.content.pojo.vo.CategoryStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class CategoryRepositoryImpl implements ICategoryRepository {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public int insert(Category category) {
        return categoryMapper.insert(category);
    }

    @Override
    public int countByName(String name) {
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        wrapper.eq("name" , name);
        return categoryMapper.selectCount(wrapper);
    }

    @Override
    public int updateById(Category category) {
        return categoryMapper.updateById(category);
    }

    @Override
    public CategoryStandardVO getStandardById(Long id) {
        return categoryMapper.getStandardById(id);
    }
}
